package com.example.mountainwalker.controller;

import com.example.mountainwalker.entity.ManagerInfo;
import com.example.mountainwalker.service.ManagerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/man")
@CrossOrigin
public class ManagerController {
    @Autowired
    private ManagerService managerService;

    @GetMapping("/find")
    public ResponseEntity<ManagerInfo> getManagerById(@RequestParam Integer id) {
        return ResponseEntity.ok(managerService.getManagerInfoById(id));
    }

    @DeleteMapping("/delete")
    public ResponseEntity<Integer> deleteManagerById(@RequestParam Integer id) {
        return ResponseEntity.ok(managerService.deleteManagerInfoById(id));
    }

    @PostMapping("/insert")
    public ResponseEntity<Integer> insertManagerInfo(@RequestBody ManagerInfo managerInfo) {
        System.out.println("接收到的数据：" + managerInfo);
        return ResponseEntity.ok(managerService.insertManagerInfo(managerInfo));
    }

    @PostMapping("/login")
    public ResponseEntity<Boolean> loginManager(@RequestBody ManagerInfo managerInfo) {
        boolean isValid = managerService.validateManager(managerInfo.getAdminName(), managerInfo.getAdminPassword());
        return ResponseEntity.ok(isValid);
    }
}